package com.lyf.lottery.controller;


import com.github.pagehelper.PageInfo;
import com.lyf.common.api.CommonPage;
import com.lyf.common.api.CommonResult;
import com.lyf.lottery.controller.assembler.OptActivityAssembler;
import com.lyf.lottery.model.po.OptActivity;
import com.lyf.lottery.model.req.OptActivityQuery;
import com.lyf.lottery.model.vo.OptActivityAddVo;
import com.lyf.lottery.model.vo.OptActivityQueryVo;
import com.lyf.lottery.model.vo.OptActivityUpdateVo;
import com.lyf.lottery.model.vo.OptActivityVo;
import com.lyf.lottery.service.OptActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *  OptActivity 接口
 * @author lyf
 **/
@RestController
@Api(tags = "OptActivity接口")
@RequestMapping("/optActivity/")
public class OptActivityController {

	@Autowired
	private OptActivityService optActivityService;

	@PostMapping("add")
	@ApiOperation("添加")
	public CommonResult add(@Validated @RequestBody OptActivityAddVo optActivityAddVo) {
		OptActivity entity = OptActivityAssembler.INSTANCE.getOptActivity(optActivityAddVo);
		optActivityService.insert(entity);
		return CommonResult.success(true);
	}

	@PostMapping("update")
	@ApiOperation("修改")
	public CommonResult update(@Validated @RequestBody OptActivityUpdateVo optActivityUpdateVo) {
		OptActivity entity = OptActivityAssembler.INSTANCE.getOptActivity(optActivityUpdateVo);
		optActivityService.update(entity);
		return CommonResult.success(true);
	}
	@PostMapping("putOn/{id}")
	@ApiOperation("上架")
	public CommonResult putOn(@PathVariable("id")Integer id) {
		return optActivityService.putOn(id);
	}
	@PostMapping("putDown/{id}")
	@ApiOperation("下架")
	public CommonResult putDown(@PathVariable("id")Integer id) {
		return optActivityService.putDown(id);
	}
	@GetMapping("list")
	@ApiOperation("获取列表")
	public CommonResult<CommonPage<OptActivityVo>> selectPage(OptActivityQueryVo optActivityQueryVo) {
		OptActivityQuery query = OptActivityAssembler.INSTANCE.getOptActivityQuery(optActivityQueryVo);
		PageInfo<OptActivity> pageInfo = optActivityService.selectPage(query);
		PageInfo<OptActivityVo> resultPage = OptActivityAssembler.INSTANCE.convertPageInfo(pageInfo);
		return CommonResult.success(CommonPage.restPage(resultPage));
	}
	@PostMapping("draw/{id}")
	@ApiOperation("抽奖")
	public CommonResult draw(@PathVariable("id")Integer id) {
		return optActivityService.draw(id);
	}
}

